﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace Simple.Repository.Models
{
    /// <summary>
    /// 食谱详情
    /// </summary>
    public class RecipesDetails : BusinessFullEntityBase<Guid>
    {


        /// <summary>
        /// 食物重量
        /// </summary>
        public decimal Weight { get; set; }

        /// <summary>
        /// 食谱id
        /// </summary>
        public Guid RecipesId { get; set; }

        /// <summary>
        /// 食材id
        /// </summary>
        public Guid FoodMaterialsId { get; set; }

        public FoodMaterials? FoodMaterials { get; set; }

        public Recipes? Recipes { get; set; }

        public override void ConfigureEntity(ModelBuilder builder)
        {
            builder.Entity<RecipesDetails>(entity =>
            {
                entity.HasOne(c => c.FoodMaterials).WithMany(c => c.RecipesDetailsList).HasForeignKey(c => c.FoodMaterialsId);
                entity.HasOne(c => c.Recipes).WithMany(c => c.RecipesDetailsList).HasForeignKey(c => c.RecipesId);

                entity.HasOne(c => c.Recipes).WithMany(c => c.RecipesDetailsList).HasForeignKey(c => c.RecipesId);
            });
            builder.Entity<Recipes>().HasMany(b => b.RecipesDetailsList).WithOne(p => p.Recipes).OnDelete(DeleteBehavior.Cascade);
        }
    }
}
